﻿using System;

using BLL;
using Model;
using Utility;

namespace EvaluationSystem
{
    public partial class EnterpriseLogin : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                txtName.Focus();
            }
        }

        protected void btnLogon_Click(object sender, EventArgs e)
        {
            string username = txtName.Text.Trim().ToLower();
            string password = txtPwd.Text.Trim().ToLower();

            EnterpriseUser enterpriseUser = new EnterpriseUser();
            enterpriseUser.Username = username;
            enterpriseUser.Password = password;

            EnterpriseUserBLL enterpriseBll = new EnterpriseUserBLL();

            if (enterpriseBll.CheckLogin(enterpriseUser))
            {
                if (txtValidate.Text.ToUpper().Equals(Session["CheckCode"].ToString()))
                {
                    /*设置session变量username为用户名*/
                    Session["username"] = username;
                    Session["EuserID"] = enterpriseBll.GetEnterpriseIdByUser(username);
                    Session["usertype"] = "E";//E - 企业端，S-系统端，A-答题端
                    Session["userfullName"] = enterpriseBll.GetIncNameByUser(username);

                    Response.Redirect("~/Enterprise/ManageActivity.aspx");
                }
                else
                {
                    MessageBox.ShowAndRedirect(this, "您输入的验证码有误，请重新输入！", "EnterpriseLogin.aspx");
                }
            }
            else
            {
                MessageBox.ShowAndRedirect(this, "您输入的用户名称或者密码有误，请重新输入！", "EnterpriseLogin.aspx");
            }
        }
    }
}
